#include "stdafx.h"
#include "Client.h"

void ClientObject::OnExit()
{
	LOG4CXX_DEBUG(Logger::getRootLogger(), "Thread ID:" << mID << ", Exit!");
	long temp;
	ReleaseSemaphore(exitSemaphore, 1, &temp);
}

void ClientObject::Run()
{
	WaitForSingleObject(exitSemaphore,INFINITE);
	LOG4CXX_DEBUG(Logger::getRootLogger(), "Thread ID:" << mID << ", Start.");
	
	while (!IsBreak ())
	{
		try
		{
			LOG4CXX_DEBUG(Logger::getRootLogger(), "Thread ID : " << mID << ", Running.");
			WaitForSingleObject(mEvent,INFINITE);
			ResetEvent(mEvent);
			{
				HT_CS(mMutex);
				if (mFunc != NULL)
				{
					mFunc(mArg);
					mFunc = NULL;
				}
			}
		}
		catch (...)
		{
			break;
		}
	}
}